package com.magic.gre.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.magic.gre.R;
import com.magic.gre.entity.ChooseUnitBean;
import com.magic.gre.ui.activity.AnswerActivity;
import com.magic.gre.ui.activity.WordsDetailsActivity;
import com.noname.lib_base_java.adapter.CommonAdapter;
import com.noname.lib_base_java.adapter.ViewHolder;
import com.noname.lib_base_java.util.L;

import java.util.List;

/**
 * Author: Lmoumou
 * Date: 2019-01-08 10:27
 * 文件名: ChooseUnitAdapter
 * 描述:
 */
public class ChooseUnitAdapter extends CommonAdapter<ChooseUnitBean> {
    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public ChooseUnitAdapter(Context mContext, List<ChooseUnitBean> mData) {
        super(mContext, mData);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(mInflater.inflate(viewType, parent, false));
    }

    @Override
    protected void bindData(ViewHolder holder, final int position) {
        final ChooseUnitBean bean = mData.get(position);

        holder.setText(R.id.content_tv, bean.getName());


        holder.getView(R.id.content_tv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(bean.getId(), bean.getName());
                }
            }
        });

        if (getItemViewType(position) == R.layout.item_choose_unit_test) {
            holder.getView(R.id.shadow2).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onItemClickListener != null) {
                        onItemClickListener.onToTest(bean.getId());
                    }

                }
            });
        }

    }

    @Override
    public int getItemViewType(int position) {
        if (mData.get(position).getStatus() == 1) {
            return R.layout.item_choose_unit;
        } else {
            return R.layout.item_choose_unit_test;
        }
    }

    public interface OnItemClickListener {
        void onItemClick(String id, String name);

        void onToTest(String id);
    }
}
